<?php
/**
 * ============================================================================
 * 版权所有 多多科技，保留所有权利。
 * 网站地址: http://soft.duoduo123.com；
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和使用；
 * 不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
*/

if(!defined('INDEX')){
	exit('Access Denied');
}

function act_wap_goods2(){
	global $duoduo,$dd_tpl_data;
	$webset = $duoduo->webset;
	$dduser = $duoduo->dduser;
	
	include(DDROOT.'/comm/goods.class.php');
	$goods_class=new goods($duoduo);
	
	$page=$_GET['page']?$_GET['page']:1;
	$code=$_GET['code'];
	$cid=(int)$_GET['cid'];
	$pagesize=10;
	$fromnum=($page-1)*$pagesize;
	
	$bankuai=dd_get_cache('bankuai');
	$where='1';
	$title='全部商品';
	
	if($code!=''){
		$where.=' and code="'.$code.'"';
		$title=$bankuai[$code]['title'];
	}
	if($cid>0){
		$where.=' and cid="'.$cid.'"';
		$title=$bankuai[$code]['title'];
	}
  $q=$_GET['q'];
	if($q!=''){
		$where.=' and title like "%'.$q.'%"';
	}
	$shuju_data=$goods_class->index_list(array('code'=>$code),$pagesize,$page,'(laiyuan_type in(1,2) or domain="jd.com") and '.$where);
	foreach($shuju_data as $k=>$row){
	if($row['is_new']){
	$shuju_data[$k]['xin']='<span class="xinpin"></span>>';
	 }
	 else{
	 $shuju_data[$k]['xin']='';
	 }
	if($row['price_man']>0){
	 $shuju_data[$k]['quan_hou']='<span class="title-tips01">券后</span>';
	 $shuju_data[$k]['youhuiquan']='<a href="'.$lq_url.'"><div class="quan_img"><span class="num_money left">'.$row['price_jian'].'</span></div></a>';
	 }
	 else{
	 $shuju_data[$k]['quan_hou']='';
	 $shuju_data[$k]['youhuiquan']='';
	 }
	 if($row['fanli']>0){
	 $shuju_data[$k]['quanhoujia']=''.$row['discount_price']-$row['price_jian'].'';
	 }else{
	 $shuju_data[$k]['quanhoujia']=''.$row['discount_price'].'';
	 }
					
		if($row['id']){
			$shuju_data[$k]['url']=wap_l('goods','view',array('id'=>$row['id'],'rec'=>$dduser['id']));
		}
		else{
			$shuju_data[$k]['url']=wap_l('goods','view',array('iid'=>$row['data_id'],'rec'=>$dduser['id']));
		}
		$shuju_data[$k]['bankuai_title']=$bankuai[$row['code']]['title'];
		$shuju_data[$k]['img']=tb_img($row['img'],500);
		$shuju_data[$k]['quan_price']=$row['discount_price']-$row['price_jian'];
	}
	
	if(AJAX==1){
		echo dd_json_encode(array('s'=>1,'r'=>$shuju_data));
		dd_exit();
	}

	$parameter['shuju_data']=$shuju_data;
	$parameter['code']=$code;
	$parameter['title']=$bankuai[$code]['title'];
	$parameter['webtitle']=$q.'';
	unset($duoduo);
	unset($webset);
	unset($dduser);
	unset($dd_tpl_data);
	return $parameter;
}
?>
<?php
if (!defined('INDEX')) {
	exit ('Access Denied');
}
$parameter=act_wap_goods2();
extract($parameter);
$cid=(int)$_GET['cid'];
$goods_type=$duoduo->select_all("type","id,title","tag='goods'".$where_type." order by sort=0 asc,sort asc,id desc");
	foreach($goods_type as $k=>$vo){
		$canshu=array();
		if($bankuai_code){
			$canshu['code']=$bankuai_code;
		}
		$canshu['cid']=$vo['id'];
		if($_GET['do']){
			$canshu['do']=$_GET['do'];
		}
		$goods_type[$k]['url']=u('goods','index',$canshu);
	}
include(TPLPATH.'/inc/header_2.tpl.php');?>
<script type="text/javascript">
            $(document).ready(function(){$("#helloDiv").hide(); });
            function changeDisplay(){
                var helloDivObj = $("#helloDiv");
                var buttonObj = $("#btnDisplay");
                var val = buttonObj.attr("value");
                if(val=="收起"){
                    helloDivObj.hide();
                    buttonObj.attr("value","分类查找");
                }else{
                    helloDivObj.show();
                    buttonObj.attr("value","收起");
                }
    }
</script>
<style type="text/css">
.lanmutop{ width:100%;max-width:750px; position:fixed;top:-2px;z-index:999;}
.lanmu2{ width:100%;font-size:14px;background:#fff;z-index:90;}
.lanmu2 li{ float:left;width:20%;text-align:center;height:38px; line-height:38px;background:#FFFFFF;border-bottom:1px #eee solid;}
.lanmu2 li a{color:#555;}
.lanmu2 li .jx{color:#ff3366;height:36px; border-bottom:2px #ff3366 solid; display:block}
.lanmu3{ width:100%;font-size:14px;background:#fff;z-index:90; }
.lanmu3 li{ float:left;width:25%; text-align:center;height:48px; line-height:38px;background:#FFFFFF;padding:10px 0 0 0}
.lanmu3 li a{color:#555;border:1px #eee solid; padding:8px 14px;border-radius:5px;}
.lanmu3 li .jx{color:#ff3366;border:1px #ff3366 solid; padding:8px 20px;border-radius:5px;}
</style>
<script>
var floorStep=2;
var ajaxTag=0;
$(function(){
	$(window).bind('scroll',function(){
		if($(window).scrollTop()+$(window).height()>=$(document).height()-400){
			if(ajaxTag==0){
				ajaxTag=1;
				jiazai(floorStep);
				floorStep++;
			}
		}
	});
	$('.shuju_load img.lazy').lazyload({
		threshold:20,
		failure_limit:50
	});
});

function index_tpl(){/* <li class="claer">   <a href="{$url}">
		            <span class="tupian"> <img data-original="{$img}" title="{$title}" class="lazy" src="<?=$dd_tpl_data['loading_img']?>" alt="{$title}" border="0"/> </span>   {$xin}</a>
					{$youhuiquan}
              <a href="{$url}"><span class="biaoti">{$title}</span></a>
                         <span class="jiage">
		                 {$quan_hou}  <span>￥</span>{$quanhoujia}
		                  <del>{$price}</del>
		                <span class="baoyou">{$laiyuan}</span> </span>
						 <?php if($row['fanli']>0){?>  <div class="fanlibao"> 
                   <span class="fanli"> <?php if($dd_tpl_data['fl-kg']['open']==0){?>  返利<span> {$fanli_je}</span> <?php }else{?> 热销 <span>{$sell}</span> 件<?php }?></span>
				</div> <?php }?>
                    </li>*/;}

function jiazai(floorStep){	
	$('.chakan_more').text('数据获取中……');
	var url='<?=wap_l(MOD,ACT)?>&code='+'<?=$code?>'+'&q='+'<?=$_GET['q']?>'+'&cid='+'<?=$_GET['cid']?>'+'&page='+floorStep;
	$.getJSON(url,function(data){
		ajaxTag=0;
		if(data.s=='1'){
			if(data.r=='' || data.r=='null' || data.r==null){
				alert('没有了');
				ajaxTag=1;
				$('.chakan_more').hidden();
			}
			else{
				for(i in data.r){
					row=data.r[i];
					var html=getTplObj(index_tpl,row);
					$('.shuju_load').append(html);
				}
				$('.chakan_more').text('点击更多');
				$('.shuju_load img.lazy').lazyload({
					threshold:20,
					failure_limit:50
				});
			}
		}
	});
}
</script>
<div class="lanmutop">
<div class="yingdao" align="center">
  <p><b>
  <?=$q?>精选</b><a href="javascript:;" onclick="history.back()" title="返回" class="left"></a> <a href='<?=wap_l('user','index')?>' title="会员中心" class="right"></a> </p></div>  
  <div class="lanmu2">
<li><a href="<?=wap_l('goods','index',array('code'=>'chaofan'))?>" <?php if($code=='chaofan'){?>class="jx"<?php }?>>超级返利</a></li>
<li><a href="<?=wap_l('goods','index',array('code'=>'quan'))?>" <?php if($code=='quan'){?>class="jx"<?php }?>>优惠券</a></li>
<li><a href="<?=wap_l('goods','index',array('code'=>'jiu'))?>" <?php if($code=='jiu'){?>class="jx"<?php }?>>9.9包邮</a></li>
<li><a href="<?=wap_l('goods','index',array('code'=>'shijiu'))?>" <?php if($code=='shijiu'){?>class="jx"<?php }?>>20元封顶</a></li>
<li style=" float:right; text-align:center;"><input id="btnDisplay" type="button" value="分类查找" onclick="changeDisplay()" style="border-radius:5px;background:#ff3366;color:#fff;border:#ff3366 solid;"></li>
</div>  <div class="lanmu3">
<div id="helloDiv">
 <?php foreach($goods_type as $vo){?>
<li><a href="<?=wap_l('goods','index',array('code'=>$_GET['code'],'cid'=>$vo['id']))?>" <?php if($_GET['cid']==$vo['id']){?>class="jx"<?php }?>><?=$vo['title']?></a></li> <?php }?> 
</div>
<br>
</div></div>


    <div class="p5" style="margin-top:76px">
    <ul class="remai2 shuju_load">
		 	  <?php foreach($shuju_data as $k=>$row){?>
		     <li class="claer">   <a href="<?=$row['url']?>">
		            <span class="tupian"> <img data-original="<?=tb_img($row['img'],500)?>" title="<?=$row['title']?>" class="lazy" src="<?=$dd_tpl_data['loading_img']?>" alt="<?=$row['title']?>" border="0"/> </span>   <?php if($row['is_new']){?><span class="xinpin"></span>  <?php }?>  </a>
					<?php if($row['price_man']>0){?>
					<a href="<?=$row['lq_url']?$row['lq_url']:'javascript:void(0)'?>"><div class="quan_img"><span class="num_money left"><?=$row['price_jian']?></span></div></a>  <?php }?>
              <a href="<?=$row['url']?>"><span class="biaoti"><?=$row['title']?></span></a>
                         <span class="jiage">
		                  <?php if($row['price_man']>0){?> <span class="title-tips01">券后</span><?php }?>  <span>￥</span>
						  <?=$row['quanhoujia']?>
		                   <?php if($code=='zhidemai'){?>  <?php }else{?> <del><?=$row['price']?></del> <?php }?>
		                <span class="baoyou"><?=$row['laiyuan']?></span> </span>
		                <span class="baoyou"><?=$row['laiyuan']?>asdasd</span> </span>
						<?php if($row['laiyuan'] == "天猫") {?><img src="tmall_ico.png" /><?php } ?>
						<?php if($row['laiyuan'] == "京东商城") {?><img src="jd_ico.png" /><?php } ?>
						<?php if($row['laiyuan'] == "淘宝") {?><img src="tb.png" /><?php } ?>
						<?php if($row['laiyuan'] == "苏宁易购") {?><img src="pai_ico.png" /><?php } ?>
                    </li>
             <?php }?>
			 </ul>
			 
</div>
 <div style="height:10px;line-height:10px; clear:both"></div>
<div class="quso">没有找到满意的商品？<span><a href="<?=wap_l('tao','search',array('q'=>''.$webtitle.''))?>">去淘宝看看</a></span></div>
<!--<a class="chakan_more">下拉加载更多</a>-->
<div class="megas513" style="padding:10px; ">
  <?=pageft($total,$pagesize,wap_l(MOD,ACT,array('code'=>$code)),WJT)?>
</div>
 <div style="height:45px;line-height:45px; clear:both"></div>
  <a href="javascript:scroll(0,0)" hidefocus="true" title="回到顶部" id="scrollTop"></a>
<?php include(TPLPATH.'/inc/tdj.tpl.php');?>
<?php include(TPLPATH.'/inc/footer.tpl.php');?>